package com.ruoyi.web.controller.linkage.equipmentBookIinkage;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.equipmentBook.Vo.EquipmentBookListVo;
import com.ruoyi.equipmentBook.domain.EquipmentBook;
import com.ruoyi.equipmentBook.service.IEquipmentBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 设备基础台账Controller
 *
 * @author pengjie
 * @date 2023-12-20
 */
@RestController
@RequestMapping("/equipmentBook/equipmentBook")
public class EquipmentBookController extends BaseController
{
    @Autowired
    private IEquipmentBookService equipmentBookService;

    /**
     * 查询设备基础台账列表
     */
    @PreAuthorize("@ss.hasPermi('equipmentBook:equipmentBook:list')")
    @GetMapping("/list")
    public PageInfo<EquipmentBook> list(@RequestBody EquipmentBookListVo equipmentBookListVo)
    {
        //startPage();
        PageHelper.startPage(Integer.parseInt(equipmentBookListVo.getPageNo()),Integer.parseInt(equipmentBookListVo.getPageSize()));
        List<EquipmentBook> list = equipmentBookService.selectEquipmentBookListByOrder(equipmentBookListVo);
        PageInfo<EquipmentBook> pageInfo=new PageInfo<>(list);
        //return getDataTable(list);
        return pageInfo;
    }

    /**
     * 导出设备基础台账列表
     */
    @PreAuthorize("@ss.hasPermi('equipmentBook:equipmentBook:export')")
    @Log(title = "设备基础台账", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EquipmentBook equipmentBook)
    {
        List<EquipmentBook> list = equipmentBookService.selectEquipmentBookList(equipmentBook);
        ExcelUtil<EquipmentBook> util = new ExcelUtil<EquipmentBook>(EquipmentBook.class);
        util.exportExcel(response, list, "设备基础台账数据");
    }

    /**
     * 获取设备基础台账详细信息
     */
    @PreAuthorize("@ss.hasPermi('equipmentBook:equipmentBook:query')")
    @GetMapping(value = "/{equipmentId}")
    public AjaxResult getInfo(@PathVariable("equipmentId") String equipmentId)
    {
        return success(equipmentBookService.selectEquipmentBookByEquipmentId(equipmentId));
    }

    /**
     * 新增设备基础台账
     */
    @PreAuthorize("@ss.hasPermi('equipmentBook:equipmentBook:add')")
    @Log(title = "设备基础台账", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EquipmentBook equipmentBook)
    {
        return toAjax(equipmentBookService.insertEquipmentBook(equipmentBook));
    }

    /**
     * 修改设备基础台账
     */
    @PreAuthorize("@ss.hasPermi('equipmentBook:equipmentBook:edit')")
    @Log(title = "设备基础台账", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EquipmentBook equipmentBook)
    {
        return toAjax(equipmentBookService.updateEquipmentBook(equipmentBook));
    }

    /**
     * 删除设备基础台账
     */
    @PreAuthorize("@ss.hasPermi('equipmentBook:equipmentBook:remove')")
    @Log(title = "设备基础台账", businessType = BusinessType.DELETE)
	@DeleteMapping("/{equipmentIds}")
    public AjaxResult remove(@PathVariable String[] equipmentIds)
    {
        return toAjax(equipmentBookService.deleteEquipmentBookByEquipmentIds(equipmentIds));
    }
}
